package com.webchat.ugc.messaegqueue.consumer.redis;

import com.webchat.common.enums.QueueMessageActionEnum;
import com.webchat.common.enums.messagequeue.MessageQueueEnum;
import com.webchat.common.service.messagequeue.consumer.AbstractRedisQueueConsumer;
import com.webchat.common.util.JsonUtil;
import com.webchat.domain.dto.queue.MallUserCartMessageDTO;
import com.webchat.ugc.service.mall.MallUserCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MallUserCartRedisQueueConsumer extends AbstractRedisQueueConsumer<MallUserCartMessageDTO> {


    @Autowired
    private MallUserCartService mallUserCartService;

    @Override
    protected MallUserCartMessageDTO convert(String s) {

        return JsonUtil.fromJson(s, MallUserCartMessageDTO.class);
    }

    @Override
    protected MessageQueueEnum getMessageQueue() {

        return MessageQueueEnum.QUEUE_MALL_USER_CART_UPDATE_MESSAGE;
    }

    @Override
    protected void receive(MallUserCartMessageDTO data) {
        mallUserCartService.doConsumeQueueMessage(data);
    }

    @Override
    protected void error(MallUserCartMessageDTO data, Exception ex) {
        mallUserCartService.saveFailQueueTask(data);
    }

    @Override
    protected int getRetryTimes() {
        return 1;
    }

    @Override
    protected boolean backToQueue(MallUserCartMessageDTO data) {
        return true;
    }

    @Override
    protected int getBackQueueTimes() {
        return 3;
    }
}
